package com.haoshuang.zhouzhoubang.ui.vm

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.TeamMemberBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData


class AppointMemberViewModel : BaseViewModel() {

    /**
     * 任务指派 成员列表
     */
    val getAppointMemberListData = StatefulMutableLiveData<TeamMemberBean>()
    fun getAppointMemberList(id: String?) = netRequest {
        start { getAppointMemberListData.value = StateData.Loading }
        request { ApiRepo.getTeamMemberList(id) }
        success { getAppointMemberListData.value = StateData.Success(it.data) }
        error { code, msg ->
            getAppointMemberListData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 门店长个人单指派
     */
    val personalAddAppointData = StatefulMutableLiveData<String>()
    fun personalAddAppoint(id: String?, team_member: String?) = netRequest {
        start { personalAddAppointData.value = StateData.Loading }
        request { ApiRepo.personalAddAppoint(id, team_member) }
        success { personalAddAppointData.value = StateData.Success(team_member) }
        error { code, msg ->
            personalAddAppointData.value = StateData.Error(code, msg)
        }
    }

}